<template>
  <div class="bac">
    <div class="main">
      <div class="main-header">登录</div>
      <div>
        <el-form
          ref="form"
          :model="form"
          label-width="50px"
          style="width: 400px"
        >
          <el-form-item label="账号">
            <el-input
              prefix-icon="el-icon-user"
              v-model="form.account"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input
              show-password
              prefix-icon="el-icon-lock"
              v-model="form.password"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="main-footer">
        <el-button type="primary" @click="login">登录</el-button>
      </div>
    </div>
    <div class="footer">Powered by B246</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: { account: "admin", password: "123456" },
    };
  },
  methods: {
    async login() {
      var data = { account: this.form.account, password: this.form.password };
      this.$store.dispatch("LoginFun", data).then((response) => {
        if (response.isSuccess) {
          // 前往首页
          this.$router.push("/home");
        } else {
          this.$message.error(response.errorMsg);
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.bac {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  right: 0;
  overflow: auto;
  background: #fff url("@/assets/loginback.png") no-repeat;
  background-size: cover;

  display: flex;
  align-items: center;
  justify-content: center;
  .main {
    margin: -10% 0 0 0;
    width: 500px;
    background-color: #fff;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    .main-header {
      margin: 30px 0;
      font-size: 20px;
    }
    .main-footer {
      margin: 20px 0;
      .el-button--primary {
        width: 400px;
      }
    }
  }
}
.footer {
  color: #606266;
  position: fixed;
  bottom: 30px;
  text-align: center;
}
</style>